Crate assert_json[−][src]
Expand description
A easy and declarative way to test JSON input in Rust.
assert_json! is a Rust macro heavily inspired by serde_json::json! macro. Instead of creating a JSON value from a JSON literal, assert_json! makes sure the JSON input conforms to the validation rules specified.
assert_json! also output beautiful error message when a validation error occurs.
#[test]
fn test_json_ok() {
let json = r#"
{
"status": "success",
"result": {
"id": 5,
"name": "charlesvdv"
}
}
"#;
let name = "charlesvdv";
assert_json!(json, {
"status": "success",
"result": {
"id": validators::u64(|&v| if v > 0 { Ok(())} else { Err(String::from("id should be greater than 0")) }),
"name": name,
}
}
);
}
Modules
Custom validators for different JSON types
Macros
Assert that a json value matches its validation rules
Enums
Validation error
Traits
Abstract the validation action for assert_json! macro.